package profile;

/**
 * This class represents a peak or dip in a profile
 * 
 */
public class Peak {
    
    public int start;
    public int end;
    
    private double[] arr;
    
    private double min;
    private double sum;
    public double amplitude;
    
    Peak(int start, int end, double[] arr) {
        this.start = start;
        this.end = end;
        this.arr = arr;
        
        setMin(arr);
    }
    
    /**
     * Sets the min of the peak (actually the dip in our case)
     * 
     * @param arr
     */
    private void setMin(double[] arr) {
        double min = Double.MAX_VALUE;
        for(int i = start; i <= end; i++) {
            if(arr[i] < min) {
                min = arr[i];
            }
        }
        
        this.min = min;
    }
    
    /**
     * Calculates the area under FWHM
     * 
     * @param signalAtFWHM
     * @param mean
     * @return
     */
    public double getAreaUnderFWHM(double signalAtFWHM, double mean) {
        double sum = 0;
        int width = 0;
        for(int i = start; i <= end; i++) {
            if(arr[i] < signalAtFWHM) {
                sum += arr[i];
                width++;
            }
        }
        
        return ((width * mean) - sum);
    }
    
    
    public double getSum() {
        return sum;
    }
    
    public double getMin() {
        return min;
    }

}
